package com.example.ploy4j.repository;

import com.example.ploy4j.entity.DeploymentJob;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

// Consider adding Pageable support for fetching jobs in pages
// import org.springframework.data.domain.Page;
// import org.springframework.data.domain.Pageable;

import java.util.List; // If you need simple list methods beyond Page
import java.util.Optional; // For findTopBy... methods that might not find anything
import com.example.ploy4j.entity.GitRepositoryConfig; // Import GitRepositoryConfig
import com.example.ploy4j.entity.DeploymentStatus; // Import DeploymentStatus

@Repository
public interface DeploymentJobRepository extends JpaRepository<DeploymentJob, Long> {

    // Example: Find by status
    // List<DeploymentJob> findByStatus(com.example.ploy4j.entity.DeploymentStatus status);

    // Spring Data JPA will automatically provide findAll, findById, save, delete, etc.
    // If you need pagination and sorting, you can extend PagingAndSortingRepository
    // or use Pageable in method signatures, e.g.:
    // Page<DeploymentJob> findAllByOrderByCreatedAtDesc(Pageable pageable);

    List<DeploymentJob> findAllByOrderByCreatedAtDesc();
    List<DeploymentJob> findByGitRepositoryConfigIdOrderByCreatedAtDesc(Long gitRepositoryConfigId);
    Optional<DeploymentJob> findTopByGitRepositoryConfigAndStatusOrderByCompletedAtDesc(GitRepositoryConfig gitRepositoryConfig, DeploymentStatus status);

} 